home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / matches.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  755 b   |  50 lines

  1. /*
  2.  * See if two strings match.  Returns a 0 on success, and a 1 on failure.
  3.  * This is an external program to be used in shell scripts.
  4.  */
  5.  
  6. #define STRSTR
  7.  
  8. #include <stdio.h>
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     char *strstr();
  15.     void exit();
  16.  
  17.     if (argc != 3) {
  18.         fprintf(stderr, "Usage: matches string1 string2\n");
  19.         exit(-1);
  20.     }
  21.  
  22.     if (strstr(argv[1], argv[2]))
  23.         exit(0);
  24.     exit(1);
  25. }
  26.  
  27. #ifdef STRSTR
  28. /*
  29.  * Return a pointer to the first occurrence of string str2 in str1.
  30.  * Returns a NULL if str2 is not in str1.
  31.  */
  32.  
  33. char *
  34. strstr(str1, str2)
  35. char *str1, *str2;
  36. {
  37.     int len;
  38.  
  39.     len = strlen(str2);
  40.     while (*str1) {
  41.         if (*str2 == *str1) {
  42.             if (!strncmp(str2, str1, len))
  43.                 return(str1);
  44.         }
  45.         str1++;
  46.     }
  47.     return(NULL);
  48. }
  49. #endif /* STRSTR */
  50.